/**
 * 1.本代码为云笔记web端开发小组共同拥有。
 * 2.组内成员有 聂道鑫、徐斌强、何瑞、钟倩。
 * 3.联系方式：442342707@qq.com
 */
package com.yunbiji.interceptor;

import java.util.List;

import com.jfinal.aop.Interceptor;
import com.jfinal.core.ActionInvocation;
import com.jfinal.core.Controller;
import com.yunbiji.model.Users;

/**
 * 注册拦截器类
 * @author 聂道鑫
 *
 */
public class RegisterInterceptor implements Interceptor
{
/**
 * 具体注册拦截操作及返回信息
 */
	public void intercept(ActionInvocation ai)
	{

		Controller c=ai.getController();
		if(ai.getMethodName().equals("reg"))
		{
			String tel =c.getPara("tel");
			if(Users.dao.Ifreg(tel))
			{
				ai.invoke();
			}
			else
			{
				c.setAttr("IfRegTel", "此手机号码已经被注册请填写另一个手机号码!!");
				c.keepPara("name","email","qq","tel").render("register.html");
			}
		}
		else if(ai.getMethodName().equals("updateProfile"))
		{
			String tel=c.getPara("telMem");
			if(Users.dao.Ifreg(tel))
			{
				ai.invoke();
			}
			else
			{
				if(Users.dao.getMembersTelById((int)c.getSessionAttr("idMem")).equals(tel))
				{
					ai.invoke();
				}
				else
				{
					c.setAttr("IfRegTelMem", "此手机号码已经被注册请填写另一个手机号码!!");
					c.keepPara("usernameMemValue","accountMemValue","passwordMemValue","repasswordMemValue","workMemValue","telMemValue","birthMemValue","emailMemValue","qqMemValue");
					
				}
				String tel2=c.getSessionAttr("username");
				String pIdMem=c.getSessionAttr("pIdMem");
				Integer pagenoMem = c.getSessionAttr("pagenoMem");
				List<Users> list = Users.dao.getUsers(tel2, pIdMem, pagenoMem);
				c.setAttr("pagenoMem", pagenoMem);
				c.setAttr("getMembers_Members", list);
				c.render("member.html");
			}
		}

	}
}
